from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.files import copy,rename
from os.path import join

class DtalkCppConan(ConanFile):
    name = "dtalk-cpp"
    version = "master"
    description = "dtalk c++11 实现"
    url = "https://gitee.com/l0km/dtalk-cpp"
    license = "BSD-2-Clause"
    author = "guyadong 10km0811@sohu.com"
    topics = ("dtalk", "c++11","json")

    requires = "simplemq-cpp/0.0.2-dev"

    package_type = "header-library"

    def export(self):
        copy(self,"conanfile_master.py",self.recipe_folder, self.export_folder)
        rename(self,join(self.export_folder,"conanfile_master.py"),join(self.export_folder,"conanfile.py"))

    def source(self):
        # 从远端仓库下载指定分支代码
        git = Git(self)
        clone_args = ['--branch', self.version]
        git.clone(url=self.url + ".git", args=clone_args, target=".")

    def package(self):
        # 确保当前仓库与远程仓库同步
        git = Git(self)
        self.output.info(git.run("pull"))
        copy(self, "*.h", join(self.source_folder,"include"),join(self.package_folder,"include"))
        copy(self, "*.cpp", join(self.source_folder,"include"),join(self.package_folder,"include"))
        copy(self, "*.hpp", join(self.source_folder,"include"),join(self.package_folder,"include"))
        copy(self, "*.hh", join(self.source_folder,"include"),join(self.package_folder,"include"))
        copy(self, "*.c", join(self.source_folder,"include"),join(self.package_folder,"include"))
        copy(self, "LICENSE", join(self.source_folder,"include"),join(self.package_folder,"include"))

    def package_id(self):
        self.info.clear()

    def package_info(self):
        self.cpp_info.requires=["simplemq-cpp::simplemq-cpp"]